package com.mdy.learn.tracker;

/**
 * 由该类统一管理GpsTracker 与 SensorTracker 的启动与停止
 */
public class TripTracker implements GpsTracker.OnGPSChangedListener, SensorTracker.OnSensorChangedListener {

    private GpsTracker gpsTracker;

    private SensorTracker sensorTracker;

    private TripWriter tripWriter;

    public void startTracker() {

        tripWriter = new TripWriter();

        gpsTracker = new GpsTracker();
        // 开启GPS数据采集
        gpsTracker.startLocation(this);

        sensorTracker = new SensorTracker();
        // 开启Sensor数据采集
        sensorTracker.startSensor(this);

    }


    public void stopTracker() {

        gpsTracker.stopLocation();

        sensorTracker.stopSensor();

        tripWriter.close();
    }

    /**
     * 当数据发生变化，则调用序列化器进行数据序列化
     * @param gpsEntity
     */
    @Override
    public void onGPSChanged(GpsTracker.GpsEntity gpsEntity) {
        tripWriter.writeOnGpsChanged(gpsEntity);
    }
    /**
     * 当数据发生变化，则调用序列化器进行数据序列化
     * @param sensorEntity
     */
    @Override
    public void onSensorChanged(SensorTracker.SensorEntity sensorEntity) {
        tripWriter.writeOnSensorChanged(sensorEntity);
    }
}
